# Hey Emacs, this is a -*- makefile -*-

#
# Copyright (C) 2012-2015 The Paparazzi Team
#
# Minimal makefile for arm-linux cross compiling toolchain.
# Assuming installed in default location.
#
# If HARD_FLOAT is defined try to find armhf cross compiler, otherwise default to softfloat

ifdef HARD_FLOAT
PREFIX ?= arm-linux-gnueabihf-
else
PREFIX ?= arm-linux-gnueabi-
endif

#
# if gcc can't be found in path, try the codesourcery toolchain in /usr/local/codesourcery
#
ifeq ($(shell which $(PREFIX)gcc),)
ifndef HARD_FLOAT
  TOOLCHAIN=$(shell find -L /usr/local/codesourcery -maxdepth 2 -type d -name arm-none-linux-gnueabi 2>/dev/null | head -n 1)
  ifneq ($(TOOLCHAIN),)
    PREFIX=$(shell dirname $(TOOLCHAIN))/bin/arm-none-linux-gnueabi
  endif
endif
endif

# if toolchain could not be found, print some useful info
ifeq ($(shell which $(PREFIX)gcc),)
  # no suitable toolchain found...
  ifdef HARD_FLOAT
    $(error Error: arm-linux-gnueabihf-gcc cross-compiler not found! Please install the gcc-arm-linux-gnueabihf package.)
  else
    $(error Error: arm-linux-gnueabi-gcc cross-compiler not found! Please install the gcc-arm-linux-gnueabi package.)
  endif
endif

CC    = $(PREFIX)gcc
CXX   = $(PREFIX)g++
LD    = $(PREFIX)g++
AR    = $(PREFIX)ar
CP    = $(PREFIX)objcopy
DMP   = $(PREFIX)objdump
NM    = $(PREFIX)nm
SIZE  = $(PREFIX)size
STRIP = $(PREFIX)strip

GDB = $(shell which $(PREFIX)gdb)
ifeq ($(GDB),)
GDB = $(shell which gdb-multiarch)
endif


# some general commands
RM = rm
